﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;

namespace TheGame
{
    public class Sound
    {
        public SoundEffect soundWave;
        public SoundEffectInstance soundIstance;
        int frameToPlay;
        bool ifCollide = false;
        Game1 game;
        Abe abe;
        float volume;



        public Sound(SoundEffect soundWave, int frameToPlay)
        {
            volume = 0.1f;
            this.soundWave = soundWave;
            this.frameToPlay = frameToPlay;
        }



        public Sound(SoundEffect soundWave, int frameToPlay, float volume)
        {
            this.volume = volume;
            this.soundWave = soundWave;
            this.frameToPlay = frameToPlay;
        }



        public Sound(SoundEffect soundWave, int frameToPlay,bool ifCollide,Game1 game, Abe abe)
        {
            volume = 0.1f;
            this.soundWave = soundWave;
            this.frameToPlay = frameToPlay;
            this.ifCollide = ifCollide;
            this.abe = abe;
            this.game = game;
        }



        public void Play()
        {
            if (!ifCollide)
                soundIstance = soundWave.Play(volume, 0.05f, 0.0f, false);
            else
            {  
                if (game.CurrentLevel.collision(abe).Contains(COLLISIONS.HOISTDESTRO) & !game.CurrentLevel.collision(abe).Contains(COLLISIONS.GODOWN))
                    soundWave.Play(volume);
            }
        }


        public void Stop()
        {
            soundIstance.Stop();
        }


        public bool isPlaying()
        {
            if (soundIstance != null && soundIstance.State == SoundState.Playing)
                return true;
            else
                return false;
        }
        public bool Played()
        {
            if (soundIstance != null && soundIstance.State == SoundState.Stopped)
                return true;
            else
                return false;
        }


        public int FrameToPlay
        {
            get { return frameToPlay; }
        }
    }
}
